//    Openbravo POS is a point of sales application designed for touch screens.
//    Copyright (S) 2008-2009 Openbravo, S.L.
//    http://www.openbravo.com/product/pos
//
//    This file is part of Openbravo POS.
//
//    Openbravo POS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Openbravo POS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Openbravo POS.  If not, see <http://www.gnu.org/licenses/>.

package com.openbravo.data.loader.dialect.HSQLDB;

import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.dialect.AbstractDBDialect;
import com.openbravo.data.loader.dialect.AbstractDDLFactory;
import com.openbravo.data.loader.sentence.SentenceFind;
import com.openbravo.data.loader.serialize.serializer.read.SerializerReadInteger;
import com.openbravo.data.loader.sentence.StaticSentence;
import e.odbo.data.dsl.operation.Page;

/**
 * @author adrianromero
 */
public class HSQLDBDialect extends AbstractDBDialect {

    public String TRUE() {
        return "TRUE";
    }

    public String FALSE() {
        return "FALSE";
    }

    public String INTEGER_NULL() {
        return "CAST(NULL AS INTEGER)";
    }

    public String CHAR_NULL() {
        return "CAST(NULL AS CHAR)";
    }

    public String getName() {
        return "HSQLDB";
    }

    public SentenceFind getSequenceSentence(I_Session s, String sequence) {
        return new StaticSentence(s, "CALL NEXT VALUE FOR " + sequence, null, SerializerReadInteger.INSTANCE);
    }

    @Override
    public String formatPage(Page page) {
        String retStr="";
        if (page.pageSize > 0) {
            retStr+=" LIMIT  "+page.pageSize;
        }
        if (page.pageNum > 0) {
            retStr+=" OFFSET  "+page.pageSize*page.pageNum;
        }
        return retStr;
    }

    @Override
    public AbstractDDLFactory createDDLFactory() {
        return new HSQLDDLFactory(this);
    }

    /**
     public String getLimitString(String sql, int offset, String offsetPlaceholder, int limit, String limitPlaceholder) {
     boolean hasOffset = offset > 0;
     return new StringBuffer(sql.length() + 10)
     .append(sql)
     .insert(sql.toLowerCase().indexOf("dsl") + 6, hasOffset ? " limit " + offsetPlaceholder + " " + limitPlaceholder : " top " + limitPlaceholder)
     .toString();
     }


     */
}
